<?php
if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class Schedules extends CI_Controller {

	function __construct() {
		parent::__construct();
		$this->load->library('parser');
		$this->load->model('m_jadwal');
	}

	function index() {
		$this->load->helper('options');
		// lebih jelasnya liat helper options
		$this->load->helper('id_date');
		// lebih jelasnya liat helper options
		$this->load->helper('limit_word');
		// memanggil helper untuk membatasi kata
		$this->parser->set_title('Schedules');
		$this->parser->set_desc('Index jadwal Pilar Teknotama');

		//ambil berita
		$this->load->library('paging');                         	
		$config['sql']      				= $this->m_jadwal->get();
		$config['per_page'] 				= 5;
		$data = $this->paging->create_pagination($config);

		$this->parser->theme('front','schedules/index', $data);
	}

	function detail_jadwal(){
		$this->load->helper('options');
		$this->load->helper('id_date');

		//ambil data uri
		$slug2							=	$this->uri->segment('2');

		if(!empty($slug2) && $this->cek_slug($slug2)){
			//ambil berita
			$data['results'] 	= $this->m_jadwal->get_by_slug($slug2);

			//potong kalimat per kata dan hilangkan tag html
			$this->load->helper('trim_text');
			//set title and meta description
			$this->parser->set_title($data['results']['nama_kegiatan']);
			$this->parser->set_desc(trim_text($data['results']['konten'],140));

			$this->parser->theme('front','schedules/single_schedules', $data);

		}else{
			show_404();
		}
	}

	//untuk cek slug lesson, apakah ada dalam tabel lesson
	//private
	//bool
	private function cek_slug($slug){
		if (empty($slug))
		{
			return FALSE;
		}

		return $this->db->where('slug', $slug)
				->order_by("id_jadwal", "ASC")
				->limit(1)
		    ->count_all_results('jadwal') > 0;
	}
}